package com.sunshine.homepage.service.impl;

import com.sunshine.homepage.dao.ProductsDao;
import com.sunshine.homepage.entity.Products;
import com.sunshine.homepage.service.homepageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import sunshine.commcon.util.entity.Result;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Service
public class homepageServiceImpl implements homepageService {
    
    @Resource
    private ProductsDao productsDao;
    


    @Override
    public Result<List<Products>> findAllProducts(int page, int size) {
        //无条件分页查询，只查询上架状态（status=1）的商品
        Pageable pageable = PageRequest.of(page, size);
        Products products = new Products();
        // 设置只查询上架商品
        products.setStatus(1);
        List<Products> products1 = productsDao.queryAllByLimit(products, pageable);
        log.info("查询所有上架商品: {}", products1);
        return Result.ok(products1);
    }
    
    @Override
    public Result<List<Products>> findProductsByCategory(String category) {
        // 根据分类查询上架商品
        List<Products> products = productsDao.queryByCategory(category);
        log.info("根据分类查询商品: {}, 结果: {}", category, products);
        return Result.ok(products);
    }
}